<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Register</title>
	<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
	<%@ include file="NavBar.jsp" %>
	<div class="container">
	<%  
	try {
		String registrationStatus = (String) request.getAttribute("registrationStatus");
		if(registrationStatus.equals("error"))
		{
			out.print("<div class=\"alert alert-error\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button><strong>Error!</strong> Something went wrong, please check your registration.</div>");
		}
	} catch (NullPointerException e) {
		
	}
  	%>

	<h1>Register</h1>
	<form class="form-horizontal" method="post" action="Register">

	  <% 
      String nameStatus = null;
      try { 
    	  nameStatus = new String((String) request.getAttribute("nameStatus"));
    	  if(nameStatus.equals("noNameInserted"))
	      {
    		  out.print("<div class=\"control-group error\">");
	      } else {
	    	  throw new NullPointerException ();
	      }
      }
      catch (NullPointerException e) {
    	  out.print("<div class=\"control-group\">");
      }
	  %>
	    <label class="control-label" for="inputName">Name</label>
	    <div class="controls">
	      <%
	      try { 
	    	  nameStatus = new String((String) request.getAttribute("nameStatus"));
	    	  if(nameStatus.equals("noNameInserted"))
		      {
					out.print("<input type=\"text\" id=\"inputError\" name=\"inputName\" placeholder=\"Name\">");  	  
					out.print("<span class=\"help-inline\">No name insterted</span>");	
		      }	else {
		    	  throw new NullPointerException ();
		      }
	      }
	      catch (NullPointerException e) {
	    	  out.print("<input type=\"text\" id=\"inputName\" name=\"inputName\" placeholder=\"Name\"");  	      	  
		    	try {
		    		String name = (String) request.getAttribute("name");
		    		if (name.equals("null")) {
		    			throw new NullPointerException();
		    		} else
		    		{
			    		out.print(" value=\"" + name + "\">");
		    		}
		    	} catch (NullPointerException f) {
		    		out.print(">");  
		      	}
	      }
	      %>
	    </div>
	  </div>
	  <% 
      String surnameStatus = null;
      try { 
    	  surnameStatus = new String((String) request.getAttribute("surnameStatus"));
    	  if(surnameStatus.equals("noSurnameInserted"))
	      {
    		  out.print("<div class=\"control-group error\">");
	      } else {
	    	  throw new NullPointerException ();
	      }
      }
      catch (NullPointerException e) {
    	  out.print("<div class=\"control-group\">");
      }
	  %>
	    <label class="control-label" for="inputSurname">Surname</label>
	    <div class="controls">
	      <%
	      try { 
	    	  surnameStatus = new String((String) request.getAttribute("surnameStatus"));
	    	  if(surnameStatus.equals("noSurnameInserted"))
		      {
					out.print("<input type=\"text\" id=\"inputError\" name=\"inputSurname\" placeholder=\"Surname\">");  	  
					out.print("<span class=\"help-inline\">No surname insterted</span>");	
		      }	else {
		    	  throw new NullPointerException ();
		      }
	      }
	      catch (NullPointerException e) {
	    	  out.print("<input type=\"text\" id=\"inputSurname\" name=\"inputSurname\" placeholder=\"Surname\"");  	      	  
		    	try {
		    		String surname = (String) request.getAttribute("surname");
		    		if (surname.equals("null")) {
		    			throw new NullPointerException();
		    		} else
		    		{
			    		out.print(" value=\"" + surname + "\">");
		    		}
		    	} catch (NullPointerException f) {
		    		out.print(">");  
		      	}
	      }
	      %>
	    </div>
	  </div>
	  
	  <% 
      String emailStatus = null;
      try { 
    	  emailStatus = new String((String) request.getAttribute("emailStatus"));
    	  if(emailStatus.equals("noEmailInserted") || emailStatus.equals("wrongEmailInsterted") || emailStatus.equals("alreadyInserted"))
	      {
    		  out.print("<div class=\"control-group error\">");
	      } else {
	    	  throw new NullPointerException ();
	      }
      }
      catch (NullPointerException e) {
    	  out.print("<div class=\"control-group\">");
      }
	  %>
	    <label class="control-label" for="inputEmail">Email</label>
	    <div class="controls">
	      <%
	      try { 
	    	  emailStatus = new String((String) request.getAttribute("emailStatus"));
	    	  if(emailStatus.equals("noEmailInserted"))
		      {
					out.print("<input type=\"text\" id=\"inputError\" name=\"inputEmail\" placeholder=\"Email\">");  	  
					out.print("<span class=\"help-inline\">No email insterted</span>");	
		      }	else if (emailStatus.equals("wrongEmailInsterted")) {
					out.print("<input type=\"text\" id=\"inputError\" name=\"inputEmail\" placeholder=\"Email\">");  	  
					out.print("<span class=\"help-inline\">This is not a valid mail</span>");
		      } else if (emailStatus.equals("alreadyInserted")) {
					out.print("<input type=\"text\" id=\"inputError\" name=\"inputEmail\" placeholder=\"Email\">");  	  
					out.print("<span class=\"help-inline\">This mail is already in Use</span>");
		      } else {
		    	  throw new NullPointerException ();
		      }
	      }
	      catch (NullPointerException e) {
	    	  out.print("<input type=\"text\" id=\"inputEmail\" name=\"inputEmail\" placeholder=\"Email\"");  	      	  
		    	try {
		    		String email = (String) request.getAttribute("email");
		    		if (email.equals("null")) {
		    			throw new NullPointerException();
		    		} else
		    		{
			    		out.print(" value=\"" + email + "\">");
		    		}
		    	} catch (NullPointerException f) {
		    		out.print(">");  
		      	}
	      }
	      %>
	    </div>
	  </div>


	  <% 
      String passwordStatus = null;
      try { 
    	  passwordStatus = new String((String) request.getAttribute("passwordStatus"));
    	  if(passwordStatus.equals("passwordNotMatch") || passwordStatus.equals("noPasswordInserted"))
	      {
    		  out.print("<div class=\"control-group error\">");
	      } else {
	    	  throw new NullPointerException ();
	      }
      }
      catch (NullPointerException e) {
    	  out.print("<div class=\"control-group\">");
      }
	  %>
	    <label class="control-label" for="inputPassword">Password</label>
	    <div class="controls">
	      <%
	      try { 
	    	  passwordStatus = new String((String) request.getAttribute("passwordStatus"));
	    	  if(passwordStatus.equals("passwordNotMatch"))
		      {
		    	  out.print("<input type=\"password\" id=\"inputError\" name=\"inputPassword\" placeholder=\"Password\">");  	  
		      }	else if (passwordStatus.equals("noPasswordInserted")) {
		    	  out.print("<input type=\"password\" id=\"inputError\" name=\"inputPassword\" placeholder=\"Password\">");  	  
		    	  out.print("<span class=\"help-inline\">You must specify a password!</span>");	    	
		      } else {
		    	  throw new NullPointerException ();
		      }
	      }
	      catch (NullPointerException e) {
	    	  out.print("<input type=\"password\" id=\"inputPassword\" name=\"inputPassword\" placeholder=\"Password\">");  	      	  
	      }
	      %>
	    </div>
	  </div>
	  <% 
	  String repeatedPasswordStatus = null;
      try { 
    	  repeatedPasswordStatus = new String((String) request.getAttribute("repeatedPasswordStatus"));
	   	  if(passwordStatus.equals("passwordNotMatch") || repeatedPasswordStatus.equals("noRepeatPasswordInserted"))
	   	  {
    		  out.print("<div class=\"control-group error\">");
	      } else {
	    	  throw new NullPointerException ();
	      }
      }
      catch (NullPointerException e) {
    	  out.print("<div class=\"control-group\">");
      }
	  %>
	    <label class="control-label" for="inputRepeatPassword">Repeat Password</label>
	    <div class="controls">
	      <%
	      try { 
	    	  passwordStatus = new String((String) request.getAttribute("passwordStatus"));
	    	  if(passwordStatus.equals("passwordNotMatch"))
		      {
		    	  out.print("<input type=\"password\" id=\"inputError\" name=\"inputRepeatPassword\" placeholder=\"Password\">");  	  
		    	  out.print("<span class=\"help-inline\">Password do not match</span>");	
		      }	else if (repeatedPasswordStatus.equals("noRepeatPasswordInserted")) {
		    	  out.print("<input type=\"password\" id=\"inputError\" name=\"inputRepeatPassword\" placeholder=\"Password\">");  	  
		    	  out.print("<span class=\"help-inline\">You must re-type your password</span>");		    	  
		      } else {
		    	  throw new NullPointerException ();
		      }
	      }
	      catch (NullPointerException e) {
	    	  out.print("<input type=\"password\" id=\"inputRepeatPassword\" name=\"inputRepeatPassword\" placeholder=\"Password\">");  	      	  
	      }
	      %>	 
	  </div>   
	  </div>
	  <div class="control-group">
	    <div class="controls">
	      <button type="submit" class="btn">Register</button>
	    </div>
	  </div>
	</form>
</div>
	</body>
</html>